#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=1e5+5;
int n,k,a[maxn],q,x,y,z,ans;
int read(){
    int s=0;
    char ch=getchar(),last=' ';
    while(ch<'0'||ch>'9')
        last=ch,ch=getchar();
    while(ch>='0'&&ch<='9')
        s=(s<<1)+(s<<3)+(ch^48),ch=getchar();
    return last=='-'?-s:s;
}
int solve(int x){
    int l=x,r=x,res=0,v=a[x];
    while(l>1||r<n){
        while(a[l-1]<=v&&l>1)
            l--,res++;
        while(a[r+1]<=v&&r<n)
            r++,res++;
        if(l==1&&r==n)
            break;
        v=min(a[l-1],a[r+1]);
        res+=k;
    }
    return res;
}
signed main(){
    freopen("summer.in","r",stdin);
    freopen("summer.out","w",stdout);
    n=read(),k=read();
    for(int i=1;i<=n;i++)
        a[i]=read();
    a[0]=a[n+1]=1e18;
    q=read();
    while(q--){
        x=read(),y=read(),z=read();
        swap(a[x],a[x+1]);
        ans=0;
        for(int i=y;i<=z;i++)
            ans+=solve(i);
        printf("%lld\n",ans);
    }
    return 0;
}